package com.um.jdy.platform.shop.manager;

import cn.hutool.core.bean.BeanUtil;
import com.um.springboot.starter.orm.entity.Response;
import com.um.jdy.common.shop.service.ReturnSettingService;
import com.um.jdy.common.shop.entity.po.ReturnSetting;
import com.um.jdy.common.shop.entity.dto.ReturnSettingDTO;
import com.um.jdy.common.shop.entity.vo.ReturnSettingVO;
import com.um.springboot.starter.orm.manager.BaseManager;
import com.um.springboot.starter.utils.UMBeanUtils;
import org.springframework.stereotype.Component;

/**
 * 管理类：平台店铺设置
 */
@Component
public class ReturnSettingManager extends BaseManager<ReturnSettingService> {

    /**
     * 详情
     *
     * @return
     */
    public Response<ReturnSettingVO> get() {
        ReturnSetting rentSetting = service.getEntity("com_id", getComId());
        if(rentSetting == null){
            rentSetting = new ReturnSetting();
            rentSetting.setComId(getComId());
            service.save(rentSetting);
        }
        return Response.success(UMBeanUtils.copyBean(rentSetting, ReturnSettingVO.class));
    }

    /**
     * 更新
     *
     * @param id
     * @param rentSettingDTO
     * @return
     */
    public Response update(String id, ReturnSettingDTO rentSettingDTO) {
        ReturnSetting rentSetting = BeanUtil.copyProperties(rentSettingDTO, ReturnSetting.class);
        rentSetting.setShopReturnSettingId(id);
        service.updateEntity(rentSetting);
        return Response.success();
    }


}
